import Vue from 'vue'
import App from './App.vue'
import router  from './router'
import Storage from 'vue-ls'
import Antd, { version ,message } from 'ant-design-vue'
import Vuex from 'vuex'
console.log('ant-design-vue version:', version)
import 'ant-design-vue/dist/antd.less';  // or 'ant-design-vue/dist/antd.less'
import './assets/note.css'

import less from 'less'


Vue.config.productionTip = false
Vue.prototype.$message = message;
message.config({
  duration: 3,// 持续时间
  top:`20px`, // 到页面顶部距离
  maxCount: 3 // 最大显示数, 超过限制时，最早的消息会被自动关闭
});

//本地存储
const options = {
  namespace: 'vuejs__', // key键前缀
  name: 'ls', // 命名Vue变量.[ls]或this.[$ls],
  storage: 'local', // 存储名称: session, local, memory
};

// Vue.prototype.webUrl =process.env.VUE_APP_API_PROTOCOL+window.location.hostname+process.env.VUE_APP_API_PORT+ process.env.VUE_APP_API_ROOT;
//window.location.origin+
Vue.prototype.webUrl =process.env.VUE_APP_API_ROOT;//在vue下可任意使用，public  和index.html   需要使用index.html中定义的变量


Vue.use(Storage, options);
Vue.use(Antd);
Vue.use(Vuex);
Vue.use(less);

/**
 * 自定义下载指令
 * v-download
 */
Vue.directive('download', {
  inserted: (el, binding) => {
    // el.style.cssText = 'cursor: pointer;'
    el.addEventListener('click', () => {
      let link = document.createElement('a')
      let obj = binding.value
      // 这里是将url转成blob地址，
      fetch(obj.url).then(res => res.blob()).then(blob => { // 将链接地址字符内容转变成blob地址
        link.href = URL.createObjectURL(blob)
        link.download = obj.fileName?obj.fileName:'';
        document.body.appendChild(link)
        link.click()
      })
    })
  }
});

new Vue({
  router,
  render: h => h(App),
}).$mount('#app')
